<?php

namespace App\Listener\Bilibili\Success;


use App\Event\BilibiliDownloadVideoJoinJob;
use App\Event\BiliBililDownloadVideoJobSuccess;
use App\Model\BilibiliVideo;
use App\Model\BilibiliVideoPage;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;

/**
 * @Listener
 *哔哩哔哩视频下载完成事件的监听
 */
class UpdateJobLogStatusListener implements ListenerInterface
{

    public function listen(): array
    {
        return [
            BiliBililDownloadVideoJobSuccess::class
        ];
    }

    public function process(object $event)
    {
        BilibiliVideoPage::Where('aid',$event->page->aid)
        ->where('cid',$event->page->cid)->update([
           'status' => BilibiliVideoPage::DOWNLOAD_SUCCESS,
           'save_url' => $event->page->save_url
        ]);

        BilibiliVideo::Where('aid',$event->page->aid)->increment('page_count');
    }


}